package com.example.guiguiapplicatio.fragment.Fulfillment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.guiguiapplicatio.api.GetdataResponseBody.GetfulfillmentdetailApi;
import com.example.guiguiapplicatio.DataManager.GetfulfillmentitemdetailData;
import com.example.guiguiapplicatio.R;
import com.example.guiguiapplicatio.fragment.Fulfillment.adapter.FulfillmentitemsDetailAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;

public class FulfillmentitemFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String idCard;
    private String servicePackagesId;
    private String serviceItemId;
    ImageButton servic_back;
    private FulfillmentitemsDetailAdapter fulfillmentitemsDetailAdapter;
    private GetfulfillmentitemdetailData getfulfillmentitemdetailData;
    private GetfulfillmentdetailApi getfulfillmentdetailApi;
    FloatingActionButton flowupfab;
    public FulfillmentitemFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment BreakContinueFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static FulfillmentitemFragment newInstance(String param1, String param2) {
        FulfillmentitemFragment fragment = new FulfillmentitemFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            idCard = getArguments().getString("idCard");
            servicePackagesId = getArguments().getString("servicePackagesId");
            serviceItemId = getArguments().getString("serviceItemId");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
//        showCityPicker();
        View root = inflater.inflate(R.layout.fragment_fulfillment_detailed1, container, false);
        servic_back = root.findViewById(R.id.servic_back);
        RecyclerView recyclerView = root.findViewById(R.id.service_items_list);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);
        fulfillmentitemsDetailAdapter = new FulfillmentitemsDetailAdapter(new ArrayList<>(),getContext());
        recyclerView.setAdapter(fulfillmentitemsDetailAdapter);
        getfulfillmentitemdetailData = new GetfulfillmentitemdetailData(fulfillmentitemsDetailAdapter);
        getfulfillmentdetailApi = new GetfulfillmentdetailApi();
        getfulfillmentdetailApi.setCallback(getfulfillmentitemdetailData);
        getfulfillmentdetailApi.performgetfulfillmentdetail(idCard,servicePackagesId,serviceItemId);
        flowupfab = root.findViewById(R.id.flow_up_fab);
        flowupfab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("idCard", idCard);
                bundle.putString("servicePackagesId", servicePackagesId);
                bundle.putString("serviceItemId", serviceItemId);
                Navigation.findNavController(v).navigate(R.id.action_FulfillmentitemFragment_to_FulfillmentitemAddFragment,bundle);
            }
        });
        servic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("idCard", idCard);
                Navigation.findNavController(v).navigate(R.id.action_FulfillmentitemFragment_to_FulfillmenthomeFragment,bundle);
            }
        });
        return root;
    }

    @Override
    public void onResume() {
        BottomNavigationView bottomNavigationView=requireActivity().findViewById(R.id.nav_view);
        bottomNavigationView.setVisibility(View.INVISIBLE);
        //这两行代码设置隐藏底部导航栏，若要显示啧修改INVISIBLE为Visible（可见）
        super.onResume();
    }
}
